/***********************************************************
 * Product Name: ExcelQuicker
 * Copyright (c)2005, Eunge
 * Author: Eunge
 * Web Site: www.eudev.net
 * Mail/MSN: eudev.net@yeah.net
 * ********************************************************/
using System;
namespace ExcelQuicker.Framework
{
	/// <summary>
	/// Measure class. It used to set the appearance, etc Height, Width, AutoFitWidth, Alignment and so on
	/// </summary>
	[Serializable]
	public class EQMeasure: EQStyleBase  
	{
		private int mWidth = DefaultInt;
		private int mHeight = DefaultInt;
		private EQBool mAutoFitWidth = EQBool.Default;
		private EQBool mAutoFitHeight = EQBool.Default;
		private Excel.XlHAlign mHorizontalAlignment = Excel.XlHAlign.xlHAlignGeneral;
		private bool mHorizontalAlignmentFlag;
		private Excel.XlVAlign mVerticalAlignment = Excel.XlVAlign.xlVAlignCenter;
		private bool mVerticalAlignmentFlag;

		/// <summary>
		/// Set/Get horizontal alignment
		/// </summary>
		public Excel.XlHAlign HorizontalAlignment
		{
			get
			{
				return this.mHorizontalAlignment;
			}
			set
			{
				this.mHorizontalAlignment = value;
				this.mHorizontalAlignmentFlag = true;
			}
		}

		/// <summary>
		/// Set/Get vertical alignment
		/// </summary>
		public Excel.XlVAlign VerticalAlignment
		{
			get
			{
				return this.mVerticalAlignment;
			}
			set
			{
				this.mVerticalAlignment = value;
				this.mVerticalAlignmentFlag = true;
			}
		}

		/// <summary>
		/// Set/Get auto fit height
		/// </summary>
		public bool AutoFitHeight
		{
			get
			{
				return (this.mAutoFitHeight==EQBool.True)?true:false;
			}
			set
			{
				this.mAutoFitHeight = (value)?EQBool.True:EQBool.False;
			}
		}

		/// <summary>
		/// Set/Get auto fit width
		/// </summary>
		public bool AutoFitWidth
		{
			get
			{
				return (this.mAutoFitWidth==EQBool.True)?true:false;
			}
			set
			{
				this.mAutoFitWidth = (value)?EQBool.True:EQBool.False;
			}
		}

		/// <summary>
		/// Set/Get width of the range
		/// </summary>
		public int Width
		{
			get
			{
				return this.mWidth;
			}
			set
			{
				this.mWidth = EQKit.CheckRangeWidth(value);
			}
		}

		/// <summary>
		/// Set/Get height of the range
		/// </summary>
		public int Height
		{
			get
			{
				return this.mHeight;
			}
			set
			{
				this.mHeight = EQKit.CheckRangeHeight(value);
			}
		}


		/// <summary>
		/// Initialize object
		/// </summary>
		public EQMeasure(){}


		/// <summary>
		/// Initialize object
		/// </summary>
		/// <param name="width"></param>
		/// <param name="height"></param>
		public EQMeasure(int width, int height)
		{
			this.Width = width;
			this.Height = height;
		}

		/// <summary>
		/// Output this style on the excel document
		/// </summary>
		/// <param name="objRange"></param>
		protected internal override void Output(Excel.Range objRange)
		{
			this.DoBeforeOperationEvent(objRange);

			if(this.AutoFitWidth)
				objRange.Columns.AutoFit();
			
			if(this.AutoFitHeight)
				objRange.Rows.AutoFit();

			if(this.Width != DefaultInt)
				objRange.ColumnWidth = (double)this.Width;

			if(this.Height != DefaultInt)
				objRange.RowHeight = (double)this.Height;

			if(this.mHorizontalAlignmentFlag)
				objRange.HorizontalAlignment = this.mHorizontalAlignment;
			if(this.mVerticalAlignmentFlag)
				objRange.VerticalAlignment = this.mVerticalAlignment;

			this.DoAfterOperationEvent(objRange);
		}
	}
}
